import * as util from './util'

export const parseTime = (time, formatter) => {
  let str = ''
  if (util.isNumber(time)) {
    let date = new Date(time)
    formatter = formatter || 'yyyy-MM-dd hh:mm'
    str = date.format(formatter)
  } else {
    str = time
  }
  return str
}

export const parseText = (title, max) => {
  const maxLength = max || max === 0 ? max : 32
  if (title && title.length > maxLength) {
    title = title.slice(0, maxLength) + '...'
  }
  return title
}

export const parseSubject = (subjectType) => {
  subjectType = subjectType || ''
  let subject = ''
  switch (subjectType) {
    case 'yuwen':
      subject = '语文'
      break
    case 'shuxue':
      subject = '数学'
      break
    case 'yingyu':
      subject = '英语'
      break
    case 'wuli':
      subject = '物理'
      break
    case 'huaxue':
      subject = '化学'
      break
    case 'shengwu':
      subject = '生物'
      break
    case 'zhengzhi':
      subject = '政治'
      break
    case 'dili':
      subject = '地理'
      break
    case 'lishi':
      subject = '历史'
      break
    default:
      subject = subjectType
  }
  return subject
}

export const parseClassification = (classificationType) => {
  classificationType = classificationType || ''
  let classification = ''
  switch (classificationType) {
    case 'primary':
      classification = '小学'
      break
    case 'middle':
      classification = '初中'
      break
    case 'high':
      classification = '高中'
      break
    default:
      classification = classificationType
  }
  return classification
}